<?php
//error_reporting(0);

/**
 * 达人推荐管理 
 * 
 * @copyright caijian
 * @since 2012-03-21
 */


include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");


$g_cgival = array();
$g_pro = array();
$g_show = array();


function show_pro()
{
	global $g_show,$g_cgival;
	$smarty = p_get_smarty ();
	$smarty->assign ( $g_show );
	if ( $g_cgival['mod'] == 'add' || $g_cgival['mod'] == 'edit' ) {
		$smarty->display ( "foodv2/album/album_tuijian_edit.html" );
	} else {
		$smarty->display ( "foodv2/album/album_tuijian.html" );
	}
}


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;

	cgi::both($g_cgival["tab"], "tab", 1);
	cgi::both($g_cgival["s_key"], "s_key", '');
	$g_cgival["s_key"] = string::un_script_code($g_cgival["s_key"]);
	$g_cgival["s_key"] = string::un_html($g_cgival["s_key"]);

	cgi::both($g_cgival["mod"], "mod", '');
	cgi::both($g_cgival["album_id"], "album_id", 0);

}


function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	global $config;

	$g_show['tab'] = (int)$g_cgival['tab'];
	if (! $g_show['tab']) $g_show['tab'] = 1;


	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();

	$db_album_tj = new db_food_album_tuijian();

	if ( $g_cgival['mod'] == 'edit') {
		$album_id = intval($g_cgival['album_id']);
		$data = $db_album_tj->admin_get_album_tj($site_id,$album_id,$pos);			// WARRNG BY DONGPING
	} elseif( ! $g_cgival['mod'] ) {

		$data = $db_album_tj->admin_get_album_tj_list($site_id,$g_show['tab'],$g_cgival['s_key']);

		foreach ($data as &$tj) {
			$tj['position'] = $config['food_album_tj_pos'][$tj['album_tj_pos']];
		}

		$g_show['current_tj_num'] = count($data);
		$g_show['data'] = $data;
		$g_show['s_key'] = $g_cgival['s_key'];
	}


	$g_show['album_positions'] = $config['food_album_tj_pos'];
	$g_show['total_tj_num'] = $config['food_album_total_tj_num'][$g_show['tab']];

	$g_show['mod'] = $g_cgival['mod'];

}

try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/user/huser_album.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


